/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.gov.ana.entities;

import br.gov.ana.historico.AlteracaoHist;
import br.gov.ana.historico.CriacaoHist;
import br.gov.ana.historico.RegistraHistorico;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author lucas.nunes
 */
@Entity
@Table(name = "QLTTB_USUARIO_RESOLUCAO")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Usuario.findAll", query = "SELECT u FROM Usuario u ORDER BY u.ureId "),
    @NamedQuery(name = "Usuario.findByUreId", query = "SELECT u FROM Usuario u WHERE u.ureId = :ureId"),
    @NamedQuery(name = "Usuario.findByUreTxLogin", query = "SELECT u FROM Usuario u WHERE u.ureTxLogin = :ureTxLogin"),
    @NamedQuery(name = "Usuario.findByUreTxSenha", query = "SELECT u FROM Usuario u WHERE u.ureTxSenha = :ureTxSenha"),
    @NamedQuery(name = "Usuario.findByUreNm", query = "SELECT u FROM Usuario u WHERE u.ureNm = :ureNm"),
    @NamedQuery(name = "Usuario.findByLoginSenha", query = "SELECT u FROM Usuario u WHERE u.ureTxLogin = :ureTxLogin AND u.ureTxSenha = :ureTxSenha ")
})
@SequenceGenerator(name = "sequenceUsuarioResolucao", sequenceName = "SQ_QLTTB_USUARIO_RESOLUCAO", allocationSize = 1)
public class Usuario implements Serializable {

    @Id
    @NotNull
    @Basic(optional = false)
    @Column(name = "URE_ID")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceUsuarioResolucao")
    private BigDecimal ureId;
    @Size(max = 255)
    @Basic(optional = false)
    @NotNull
    @Column(name = "URE_TX_LOGIN")
    private String ureTxLogin;
    @Size(max = 255)
    @Basic(optional = false)
    @NotNull
    @Column(name = "URE_TX_SENHA")
    private String ureTxSenha;
    @Size(max = 255)
    @Basic(optional = false)
    @NotNull
    @Column(name = "URE_NM")
    private String ureNm;
    @Column(name = "URE_STATUS")
    private Integer ureStatus;
    @Size(max = 255)
    @Basic(optional = false)
    @NotNull
    @Column(name = "URE_EMAIL")
    private String ureEmail;
    @Column(name = "URE_PERMISSAO")
    private Integer urePermissao;
    @OneToMany(mappedBy = "hreUreId")
    private List<HistResolucao> histResolucaoList;

    /**
     *
     * @return
     */
    public BigDecimal getUreId() {
        return ureId;
    }

    /**
     *
     * @param ureId
     */
    public void setUreId(BigDecimal ureId) {
        this.ureId = ureId;
    }

    /**
     *
     * @return
     */
    public String getUreTxLogin() {
        return ureTxLogin;
    }

    /**
     *
     * @param ureTxLogin
     */
    public void setUreTxLogin(String ureTxLogin) {
        this.ureTxLogin = ureTxLogin;
    }

    /**
     *
     * @return
     */
    public String getUreTxSenha() {
        return ureTxSenha;
    }

    /**
     *
     * @param ureTxSenha
     */
    public void setUreTxSenha(String ureTxSenha) {
        this.ureTxSenha = ureTxSenha;
    }

    /**
     *
     * @return
     */
    public String getUreNm() {
        return ureNm;
    }

    /**
     *
     * @param ureNm
     */
    public void setUreNm(String ureNm) {
        this.ureNm = ureNm;
    }

    /**
     *
     * @return
     */
    public Integer getUreStatus() {
        return ureStatus;
    }

    /**
     *
     * @param ureStatus
     */
    public void setUreStatus(Integer ureStatus) {
        this.ureStatus = ureStatus;
    }

    /**
     *
     * @return
     */
    public String getUreEmail() {
        return ureEmail;
    }

    /**
     *
     * @param ureEmail
     */
    public void setUreEmail(String ureEmail) {
        this.ureEmail = ureEmail;
    }

    /**
     *
     * @return
     */
    public Integer getUrePermissao() {
        return urePermissao;
    }

    /**
     *
     * @param urePermissao
     */
    public void setUrePermissao(Integer urePermissao) {
        this.urePermissao = urePermissao;
    }

    @Override
    public String toString() {
        return this.ureNm + " (" + this.ureTxLogin + ")";
    }

    /**
     *
     */
    public Usuario() {
    }

    /**
     *
     * @return
     */
    @XmlTransient
    public List<HistResolucao> getHistResolucaoList() {
        return histResolucaoList;
    }

    @XmlTransient
    public CriacaoHist getHistoricoCriacao() throws Exception {
        if (getUreId() != null) {
            return new RegistraHistorico().getCriacaoHist(getUreId(), this.getClass().getName());
        }
        return null;

    }

    @XmlTransient
    public AlteracaoHist getHistoricoAlteracao() throws Exception {
        if (getUreId() != null) {
            return new RegistraHistorico().getAlteracaoHist(getUreId(), this.getClass().getName());
        }
        return null;
    }

    /**
     *
     * @param histResolucaoList
     */
    public void setHistResolucaoList(List<HistResolucao> histResolucaoList) {
        this.histResolucaoList = histResolucaoList;
    }

    @XmlTransient
    public String getHistoricoDescricao() {
        if (ureId != null) {
            return " Id: " + ureId.intValue()
                    + "; Login: " + ureTxLogin
                    + "; Nome: " + ureNm
                    + "; Email: " + ureEmail
                    + "; Permissao: " + urePermissao
                    + "; Status: " + ureStatus;

        } else {
            return "";
        }
    }
}
